// [unit] execvm "Computer\console\gps_unit.sqf"

_unit=_this select 0;

private ["_unitmarker","_timer"];

_getvehiclecolor=
{
   _v=_this select 0;
   _color="ColorWhite";         
   if(side _v == west) then {_color="ColorBlue";};
   if(side _v == east) then {_color="ColorRed";};
   if(side _v == resistance) then {_color="ColorGreen";};
   if(side _v == civilian) then {_color="ColorOrange";};
   if(count (crew _v) < 1) then {_color="ColorYellow";};
   if (!alive _v) then {_color="ColorBlack";};
   _color
};





while {(gps_eni_valid==1) and (!isnull _unit)} do
{
    //Get current markername var on the object
    _variable=_unit getVariable "vtsmakername";   
    //Make sure we don't change the variable in a loop
    if (!isnil "_variable") then {_unitmarker=_variable;};
    
    if (isnil "_unitmarker") then
    {
    
        if !(isnull _unit) then
        {
          //Creating a new marker if the unit doesnt have one
          //hint "Creating a new marker"; 
          //Checking if nmarker is initated
          if (isnil "vtsnmarker") then {vtsnmarker=0;};
          //Creating markers
          _vclass=typeOf _unit;
          
          _mtype="empty";
          _msize=[0.75,0.75];
          _timer=3.0;
          if (_vclass iskindof "Man") then {_mtype="Dot";_msize=[0.3, 0.3];};
          if (_vclass iskindof "Motorcycle") then {_mtype="n_empty"};
          if (_vclass iskindof "Tank") then {_mtype="n_armor"};
          if (_vclass iskindof "Tracked_APC" or _vlass iskindof "APC" or _vlass iskindof "Wheeled_APC") then {_mtype="n_armor"};
          if (_vclass iskindof "Ship") then {_mtype="n_empty"};
          if (_vclass iskindof "StaticWeapon") then {_mtype="n_mortar"};
          if (_vclass iskindof "Helicopter") then {_mtype="n_air";_timer=1.0;};
          if (_vclass iskindof "Car") then {_mtype="n_empty"};
          if (_vclass iskindof "Truck") then {_mtype="n_recon"};
          if (_vclass iskindof "Plane") then {_mtype="n_plane";_timer=1.0;};
          if (_vclass iskindof "ReammoBox") then {_mtype="n_service"};
          if (_vclass iskindof "Sign_sphere25cm_EP1") then {_mtype="mil_unknown";_msize=[0.3, 0.3];};
  
          
          _unitmarker = createMarkerLocal[format["AIMarker%1",vtsnmarker], getpos _unit];
          _unitmarker setMarkerTypeLocal _mtype;			
      	  _unitmarker setMarkerSizeLocal _msize;
      
          _unit setvariable ["vtsmakername",_unitmarker];
          
          //Incrementing markers
          
          vtsnmarker=vtsnmarker+1;
          };           
    };
    _mcolor=[_unit] call _getvehiclecolor;
    _unitmarker setMarkerPosLocal (getpos _unit);           
    _unitmarker setMarkerColorLocal _mcolor;
    
    sleep _timer;
};

//Cleaning up marker on exit
//hint "End of marker";

deleteMarkerLocal _unitmarker;
_unit setvariable ["vtsmakername",nil];


